var $ = getApp(), methods = require("../methods.js");
Page(Object.assign({}, methods, {
	data: {
		hiddenmodalput:true,
		userinfo: [],
		count: 0,
		count1: 0,
		count2: 0,
		count3: 0,
		count4: 0,
		comwithdrawmin: 0,
		canwithdraw: true,
		money:0
	},
	_onLoad: function (options) {
		var that = this;
		wx.setNavigationBarTitle({
			title: '我的' + (that.data.textset['佣金'] || '佣金')
		});
		$.get('agent/commissionSurvey', {}, function (res) {
			that.setData({ userinfo: res.userinfo, 
				count: res.count, count1: res.count1, count2: res.count2, count3: res.count3, count0: res.count0,
				countdqr:res.countdqr,
				comwithdrawmin: res.comwithdrawmin,
				commission2money: res.commission2money })
			var canwithdraw = (parseFloat(res.userinfo.commission) >= parseFloat(res.comwithdrawmin)) ? true : false
			that.setData({ canwithdraw: canwithdraw })
		});
	},
	cancel: function () {
		this.setData({
			hiddenmodalput: true
		});
	},
	tomoneny:function(){
		this.setData({hiddenmodalput:false});
	},
	getmoney:function(e){
		this.setData({money:e.detail.value})
	},
	tomonenyconfirm:function(){
		var that = this;
		var money = this.data.money
		if(money == '' || parseFloat(money) <=0){
			$.alert('请输入转入金额');
			return;
		}
		if(parseFloat(money) > this.data.userinfo.commission){
			$.alert('可转入'+(that.data.textset['佣金'] || '佣金')+'不足');
			return;
		}
		$.post('agent/commission2money',{money:money},function(data){
			if(data.status==0){
				$.error(data.msg);
			}else{
				that.setData({
					hiddenmodalput: true
				});
				$.success(data.msg); 
				setTimeout(function () {
						that.reLoad();
				}, 1000);
			}
		})
	}
}))